package com.sike.javacore.serializer.serializable.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Student implements Externalizable {

    private String name;

    private int age;

    private int grade;


    @Override
    public void writeExternal(ObjectOutput out) throws IOException {
        out.writeObject(name);
        out.writeInt(age - 2);      // 年龄我虚报 2 岁
        // 成绩我不报了
    }

    @Override
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        this.name = (String) in.readObject();
        this.age = in.readInt();
    }
}
